package com.hankol.winecellar.adapter

import android.content.Context
import android.os.Bundle
import android.widget.ImageView
import android.widget.LinearLayout
import com.baselibrary.Constants
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.*
import com.baselibrary.view.VipHeardImgView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.WineryEvaluateListBean
import com.baselibrary.view.PhotosContentView
import com.baselibrary.view.PhotosContentViewAdapter
import java.util.*

/*
* 酒窖详情--种草评论
* */
class WineryDetailEvaluateAdapter : BaseQuickAdapter<WineryEvaluateListBean , BaseViewHolder>(R.layout.item_evaluate_winery) {

    override fun convert(helper: BaseViewHolder , item: WineryEvaluateListBean) {
        helper.setGone(R.id.v_bottom,helper.adapterPosition!=data.size-1)
        helper.setText(R.id.tv_name , item.name.checkValue()).setText(R.id.tv_time , TimeUtil.fromToday(item.ctime))
        val heardImg = helper.getView<VipHeardImgView>(R.id.civ_cover)
        item.let {
            heardImg.setData(it.icon , it.isFans == 1);
        }
        helper.setText(R.id.tv_content , item.wineryCommentDesc.checkValue())
        val nineGridPhoto = helper.getView<PhotosContentView<String>>(R.id.photo_content_view)
        nineGridPhoto.setAdapter(object : PhotosContentViewAdapter<String>() {
            override fun onDisplayImage(context: Context , imageView: ImageView , data: String) {
                Glide.with(context).load(data).placeholder(R.drawable.ic_def_hanxiang_228).error(R.drawable.ic_def_hanxiang_228).apply(RequestOptions().transform(MultiTransformation(CenterCrop() , RoundedCorners(20)))).into(imageView)
            }

            override fun onItemImageClick(context: Context , imageView: ImageView , index: Int , list: MutableList<String>) {
                super.onItemImageClick(context , imageView , index , list)
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    SensorsDataManager.instance.cellarCommentSee(item.wineryCommentDesc)
                    //图片详情
                    val bundle = Bundle()
                    bundle.putStringArrayList(Constants.KEY_URLS , list as ArrayList<String>)
                    bundle.putInt(Constants.KEY_INDEX , index)
                    bundle.putStringArrayList(Constants.KEY_COMMENT_CONTENT , arrayListOf(item.wineryCommentDesc))
                    bundle.putStringArrayList(Constants.KEY_COMMENT_TITLE , arrayListOf())
                    ActivityRouter.startActivity(ActivityRouter.WINE_CELLAR.IMG_VIDEO_DETAIL , bundle)
                }
            }
        })
        if (item.wineryCommentImg.checkNotNull()) {
            nineGridPhoto.setImageData(item.wineryCommentImg.split(",").toMutableList())
        }
        helper.getView<VipHeardImgView>(R.id.civ_cover).setOnClickListener {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                val hashMap = HashMap<String , Any>()
                hashMap["userId"] = item.uid
                ARouterUtils.jump(ActivityRouter.MINE_CENTER.USER_INFO , hashMap)
            }
        }
        helper.getView<LinearLayout>(R.id.ll_name).setOnClickListener {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                val hashMap = HashMap<String , Any>()
                hashMap["userId"] = item.uid
                ARouterUtils.jump(ActivityRouter.MINE_CENTER.USER_INFO , hashMap)
            }
        }
    }
}